home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / MAILER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.1 KB  |  177 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Implementation of class TMailer which provides Mail enabling.
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_WINDOW_H)
  11. # include <owl/window.h>
  12. #endif
  13. #if !defined(OWL_MAILER_H)
  14. # include <owl/mailer.h>
  15. #endif
  16. #if !defined(WINSYS_PROFILE_H)
  17. # include <winsys/profile.h>
  18. #endif
  19. #include <stdio.h>
  20. #include <commdlg.h>  // GetFileTitle()
  21.  
  22. OWL_DIAGINFO;
  23.  
  24. #if defined(BI_PLAT_WIN32)
  25.   static char MapiLibName[] = "mapi32.dll";
  26. #else
  27.   static char MapiLibName[] = "mapi.dll";
  28. #endif
  29.  
  30. //
  31. // Loads the MAPI DLL.
  32. //
  33. TMailer::TMailer()
  34. :
  35.   TModule(MapiLibName, true, true),  // Should load library & must exist
  36.   MAPISendDocuments(*this, "MAPISendDocuments")
  37. {
  38. }
  39.  
  40. //
  41. // owner
  42. //   The owning window that is using the mailer. Is used to parent mail UI
  43. //   windows
  44. //
  45. // paths
  46. //   Pointer to string containg the files to send. The files must have a
  47. //   fully qualified path and filename. The string could have multiple
  48. //   files separated by a semicolon ';'.  The filenames may be long filenames.
  49. //
  50. // names
  51. //
  52. // asynchWork
  53. //   If true, the message submission will be made from a separate thread
  54. //   other than the thread where the SendMail was called.  With this flag,
  55. //   the function returns immediately after the working thread has been
  56. //   created. If false, the call is synchronous and it wll return when the
  57. //   message is submitted to the messaging subsystem.
  58. //
  59. // Purpose:
  60. //  This function is called by apps to send files to a mail recipient. The
  61. //  attachments can be of any size. The underlying messaging system will ask
  62. //  for credentials of the recipients.  When the send note is displayed, other
  63. //  options could be added or modified.  Also at that time other type of
  64. //  attachments can be added (i.e. OLE objects).
  65. //
  66. void
  67. TMailer::SendDocuments(TWindow* owner, const char far* docPaths,
  68.                        const char far* docNames, bool asynchWork)
  69. {
  70.   // Get the document names--either directly if passed, or by parsing the paths
  71.   //
  72.   char far* tmpDocNames = 0;
  73.   if (!docNames) {
  74.     // The file name must be separated by semi-colon, so parse the string for
  75.     // the sub-strings
  76.     //
  77.     char far* tmpPaths = strnewdup(docPaths);
  78.     tmpDocNames = new char[1024];
  79.     *tmpDocNames = 0;
  80.     char far* nameToken = strtok(tmpPaths, ";\n");
  81.     while (nameToken) {
  82.       // Strip leading blanks from name
  83.       //
  84.       while (*nameToken == ' ')
  85.         nameToken++;
  86.  
  87.       // Get the file name (long file names are supported) from the path
  88.       //
  89.       char tmpName[_MAX_PATH];
  90.       ::GetFileTitle(nameToken, tmpName, sizeof tmpName);
  91.  
  92.       // Append to string of file names (no paths)
  93.       //
  94.       strcat(tmpDocNames, tmpName);
  95.       strcat(tmpDocNames, ";");
  96.  
  97.       // Get the next sub-string in the files string
  98.       //
  99.       nameToken = strtok(0, ";\n");
  100.     }
  101.     delete[] tmpPaths;
  102.     docNames = tmpDocNames;
  103.   }
  104.  
  105.   // Call MAPI to send the document. This function always prompts with a
  106.   // dialog box so that the user can provide recipients and other sending
  107.   // options.  The function tries to etablish a session from the messaging
  108.   // system's shared session.  If no shared session exists, it prompts for
  109.   // logon information to establish a session.  Before the function return,
  110.   // it closes the session.
  111.   //
  112.   uint32 err = MAPISendDocuments(uint32(owner->GetHandle()), ";",
  113.                                  (char far*)docPaths,
  114.                                  (char far*)docNames,
  115.                                  asynchWork);
  116.   if (err) {
  117.     // A problem was encountered.  Report it to the user?
  118.     //
  119. //    sprintf(docNames, "Failed to send the documents. Error: %d", err);
  120. //    owner->MessageBox(docNames, 0, MB_OK);
  121.   }
  122.  
  123.   // Delete the temp names string if we new'd one here
  124.   //
  125.   delete[] tmpDocNames;
  126. }
  127.  
  128.  
  129. //
  130. // Verify whether SMAPI is properly installed and configured on this machine
  131. // by checking WIN.INI MAIL/MAPI setting
  132. //
  133. bool  
  134. TMailer::IsMAPIAvailable() const 
  135. {
  136. #if 1
  137.   TProfile mailSection("Mail");
  138.   return mailSection.GetInt("MAPI") != 0;
  139.  
  140. #else //   Do we need to perform additional checking
  141.  
  142.   static bool doneCheck = false;
  143.   static bool mailState = false;
  144.  
  145.   // Have we checked yet?
  146.   //
  147.   if (doneCheck)
  148.     return mailState;
  149.  
  150.   TProfile mailSection("Mail");
  151.  
  152.   bool mapiFlag = mailSection.GetInt("MAPI");
  153.  
  154.   if (mapiFlag && TSystem::IsWin95()) {
  155.     // If we're running on Windows 95, we have to also make sure
  156.     // Exchange is installed.
  157.     //
  158.     TAPointer<char> buffer = new char[80];
  159.     mailSection.GetString("Exchange", buffer, 80);
  160.  
  161.     if (buffer) {
  162.       strlwr(buffer);
  163.  
  164.       if (strstr(buffer, "exchng32"))
  165.         mailState = true;
  166.     }
  167.  
  168.   }
  169.   else if (mapiFlag && TSystem::IsNT()) {
  170.     mailState = true;
  171.   }
  172.  
  173.   doneCheck = true;
  174.   return mailState;
  175. #endif
  176. }
  177.